<template>
  <div>
    <input-table style="width:100%"
                 v-model="folders" @add="v=>{ v.config = { docker: {}, k8sDeployment : {} } }">
      <el-table-column align="center" label="项目路径" minWidth="280">
        <template v-slot="scope">
          <div style="display: flex;align-items: center;">
            <el-input v-model="scope.row.path" style="flex:1"
                      placeholder="点(.)表示根路径"
                      chk=": if(value.startsWith('/')) return '不能以/开头'; if(value.endsWith('/')) return '不能以/结束'; "
            />
            <span v-if="scope.row.path == '.' " style="color:red;margin-left: 10px;">提示：根目录!</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column align="center" label="spring.application.name" minWidth="220">
        <template v-slot="scope">
          <el-input v-model="scope.row.name" />
<!--                    chk=": if( value.startsWith(data.value.productLine.code) == false) return '必须以产品线编码' + data.value.productLine.code  +'开头' "-->

        </template>
      </el-table-column>

      <el-table-column align="center" label="中文名称" minWidth="160">
        <template v-slot="scope">
          <el-input v-model="scope.row.cnname"/>
        </template>
      </el-table-column>

      <el-table-column align="center" label="Dockerfile | K8sDeployment" width="260" v-if="!$model.isLib">
        <template v-slot="scope">
          <div style="display: flex;justify-content: space-between;gap:10px;">

            <el-tag
                v-if="scope.row.config?.docker?.id && !$data.dockers.some(it=>it.id == scope.row.config?.docker?.id) "
                @click="scope.row.config.docker={}">配置错误，点击fix，再保存
            </el-tag>
            <selector v-else v-model="scope.row.config.docker.id" :enum-count="0" :clearable="true"
                      :auto1="false" :data="langDockers" style="width: 160px"
                      fields="id,name" @change="(v,m)=>scope.row.config.docker.name=m.name"></selector>

            <el-tag
                v-if="scope.row.config?.k8sDeployment?.id && !$data.k8syamls.some(it=>it.id == scope.row.config?.k8sDeployment?.id) "
                @click="scope.row.config.k8sDeployment={}">配置错误，点击fix，再保存
            </el-tag>
            <selector v-model="scope.row.config.k8sDeployment.id" :enum-count="0" :clearable="true"
                      :auto1="false" style="width: 160px"
                      :data="$data.k8syamls" fields="id,name"
                      @change="(v,m)=>scope.row.config.k8sDeployment.name=m.name"></selector>
          </div>
        </template>
      </el-table-column>

    </input-table>
    <div style="line-height: 1.8" v-if="!$model.isLib">
      注：
      <br/>
      <el-tag>spring.application.name</el-tag>
      设置会覆盖程序中的值。
      <br/>
      Jenkins任务名称 = k8s pod名称 =
      <el-tag>spring.application.name</el-tag>
      -java<br/>
    </div>


  </div>
</template>
<script setup>



defineOptions({
  name: "java-list",
  inheritAttrs: true,
});

//定义 vue2的this,当前组件
const $self = getCurrentInstance();

//定义 $attrs
const $attrs = useAttrs();


//定义data
const $data = reactive({
  "dockers": [], "k8syamls": [], "row": {},
  dlg_show: false,
  dlg_row: null,
  dlg_field: null,
  dlg_input: null
});




const $model = defineModel({type: Object});



//定义事件
const $emit = defineEmits(["update:modelValue", "loaded"]);

const langDockers = $computed(function () {
  return $data.dockers.filter(it => it.language == $model.value.language)
});
const folders = $computed({
  get() {
    return $model.value.folders;
  }, set(folders) {
    var v = Object.assign({}, $model.value, {folders});
    $emit("update:modelValue", v);
  }
});

const hook_click = function (row, field) {
  $data.dlg_show = true;
  $data.dlg_row = row;
  $data.dlg_field = field;
  $data.dlg_input = $data.dlg_row[$data.dlg_field];
};
const hook_ok_click = function () {
  $data.dlg_show = false;
  $data.dlg_row[$data.dlg_field] = $data.dlg_input;
};

onMounted(function () {
  jv.$http.post("/dev/user-dockerfile/list?excludes=dockerfile").then(res => {
    $data.dockers = res.data.data;
  });
  jv.$http.post("/dev/user-k8s-deployment/list?excludes=yaml").then(res => {
    $data.k8syamls = res.data.data;
  });
})


</script>